package com.ziyueyuwen.xiniao.annotation.validator;

import com.ziyueyuwen.xiniao.annotation.ParamValidated;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

import static com.ziyueyuwen.xiniao.base.BaseUtil.checkParam;

/**
 * @author wancheng  on 2019/1/19.
 */
public class ParamValidator implements ConstraintValidator<ParamValidated,Object> {

    private Logger logger = LoggerFactory.getLogger(getClass());


    @Override
    public void initialize(ParamValidated constraintAnnotation) {
        logger.info("初始化StringValidated注解");
    }

    @Override
    public boolean isValid(Object obj, ConstraintValidatorContext constraintValidatorContext) {
        //返回false代表校验失败，true代表校验通过
        try {
            checkParam("",obj);
        }catch (Exception e){
            return false;
        }
        return true;
    }

}
